import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'lib-flexible'
import QMP from '@/plugins/qmp-ui'
import 'qy-tokens/baseStyle.css'
import './assets/styles/qmp-ui.less'
import { DevConfig, nativeHandler, judgeSys } from 'qmp-native'
import { getCookieToken } from '@/utils/auth'
import { Toast, Dialog } from 'qmp-component'
import { SimpleEvents } from '@/utils'

const app = createApp(App)

// 添加全局方法
app.config.globalProperties.$nativeHandler = nativeHandler
app.config.globalProperties.$judgeSys = judgeSys
app.config.globalProperties.$toast = Toast
app.config.globalProperties.$loading = Toast.loading
app.config.globalProperties.$dialog = Dialog
app.config.globalProperties.$SimpleEvents = SimpleEvents

console.log(process.env)
if (process.env.QMP_EVN === 'development') {
  DevConfig.useDefaultData = true // 开发环境调用原生方法时，使用是否使用默认数据
  // 开发环境默认数据配置
  DevConfig.defaultData = {
    '': {
      token: `Bearer ${getCookieToken()}`
    },
    // nativeHandler('getBaseInfo') 接口在测试环境返回的数据
    getBaseInfo: {
      account: 'yuhao1',
      userName: '土豪'
    },
    // 调用原生其他接口 返回的数据
    default: {
      property1: 'value1',
      property2: 'value2'
    }
  }
}

// 注册qmp-ui组件
const qmpComponents = [...QMP.components]
qmpComponents.forEach((i) => app.use(i))
app.use(store).use(router).mount('#app')

// 自定义路由返回方法（用于实现返回页面过渡动画）
router.goBack = () => {
  router.isBack = true
  window.history.go(-1)
}
